"""
调用三方服务发送短信
"""
import random

import requests


def get_mobile_code(length=6):
    return ''.join(random.choices('0123456789', k=length))


def send_message(tel, code):
    resp = requests.post(
        url='http://sms-api.luosimao.com/v1/send.json',
        auth=('api', 'key-a191efa9e007373daf2c838a98533405'),
        data={
            'mobile': tel,
            'message': f'您的短信验证码是{code}，打死也不能告诉别人哟！【Python小课】'
        },
        timeout=3
    )
    return resp.json()


if __name__ == '__main__':
    code = get_mobile_code()
    print(code)
    print(send_message('13548041193', code))
